package uiLayer.uiBooking;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.Dialog.ModalityType;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import modelLayer.Booking;

public class BookingRUdialog extends JDialog {

	private BookingCard1 contentPanel;
	private Booking booking;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			BookingRUdialog dialog = new BookingRUdialog(null, null);
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 */
	public BookingRUdialog(JFrame frame, Booking b) {
		super(frame);
		this.booking = b;
		contentPanel = new BookingCard1(booking);
		setModalityType(ModalityType.APPLICATION_MODAL);
		Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
		int width = 1100;
		int height = 650;
		int X = (screen.width / 2) - (width / 2); // Center horizontally.
		int Y = (screen.height / 2) - (height / 2); // Center vertically.
		setBounds(X, Y, width, height);
		
		setTitle("Rediger booking");
		
		getContentPane().setLayout(new BorderLayout());
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		
		JButton btnSave = contentPanel.getBtnSave();
		btnSave.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				updateBooking();
			}
		});
		
		JButton btnCancel = contentPanel.getBtnCancel();
		btnCancel.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				cancelAction();				
			}
		});
		
	}
	
	protected void updateBooking() {
		if(contentPanel.saveBooking()) {
			super.dispose();
		}
		
		
	}
	
	

	protected void cancelAction() {
		//super.setVisible(false);
		super.dispose();
	}

}
